package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseSaleAttr;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.BaseSaleAttrService;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:lyd
 * @Date:2023/8/16 15:56
 * @Version:1.0
 * @Description
 **/
@RestController
@RequestMapping("/admin/product")
public class BaseSaleAttrController {


    @Autowired
    private BaseSaleAttrService baseSaleAttrService;

    @Autowired
    private SpuSaleAttrService spuSaleAttrService;
    /**
     * 获取销售属性列表
     * @return
     */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList() {
        List<BaseSaleAttr> list = baseSaleAttrService.list();
        return Result.ok(list);
    }

    /**
     * 根据spuId获取销售属性及其对应的值
     * @param spuId
     * @return
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result getSpuSaleAttrList(@PathVariable Long spuId) {
        List<SpuSaleAttr> list=spuSaleAttrService.getSpuSaleAttrList(spuId);
        return Result.ok(list).message("成功");
    }
}
